import "babel-polyfill";
import Vue from 'vue';
import App from './App';
import router from './router';
import store from './store';
import VueI18n from 'vue-i18n';
import ViewUI from 'view-design';
import "@/assets/iconfont/iconfont.css";
// import '@/utils/xtxasyn.js';

// import CA from "./utils/ca.js";
// Vue.prototype.$CA = new CA();
 
// 全局公共样式
import 'view-design/dist/styles/iview.css';
import '../my-theme/index.less';
import {
	Button, Select, Option, Message, Notice,
	Modal, Row, Col, Icon, Input, Table, Page,
	Form, FormItem, InputNumber, Upload, Checkbox,
	CheckboxGroup, Switch, CellGroup, Cell, Tabs
} from 'view-design';
import './assets/css/base.css';
import axios from './plugins/http';
/* aes 对称加密 */
import aesUtils from '@/plugins/aes-utils.js';
Vue.prototype.aesUtils = aesUtils;
//注册全局过滤器
import * as filters from "@/plugins/filter.js";
Object.keys(filters).forEach(key => {
	Vue.filter(key,filters[key]);
});

import preview from 'vue-photo-preview';
import 'vue-photo-preview/dist/skin.css';
import BaiduMap from 'vue-baidu-map'
 
Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'vqP7LHN9LD033eGnrpFDdvvD'
})
Vue.use(preview);
Vue.use(ViewUI);

//注册全局函数
import {GetDate,uploadFileDecrypt,findStr,addZeros,analysisImages,functionJS,packageAxios,deletekey,getNewData,removeHTMLTag} from "@/commons/function.js";

Vue.prototype.GetDate = GetDate;
Vue.prototype.uploadFileDecrypt = uploadFileDecrypt;
Vue.prototype.findStr = findStr;
Vue.prototype.addZeros = addZeros;
Vue.prototype.pictureFormat = analysisImages;
Vue.prototype.getNewData = getNewData;
Vue.prototype.functionJS = functionJS;
Vue.prototype.removeHTMLTag = removeHTMLTag;
Vue.prototype.packageAxios = packageAxios
Vue.prototype.deletekey = deletekey
//设置title
router.beforeEach((to, from, next) => {
	if(store.state.env == "production" || store.state.env == "test"){
		if(to.path != "/login"){
			let access_token = window.localStorage.getItem("access_token");
			if(to.path == "/changerpass"){
				next();
			}else{
				if(access_token != undefined){
					
					let title = to.meta.title ? to.meta.title : "运营管理平台";
					document.title = title;
					next();
				}else{
					next("/login");
				}
			}
		}else{
			next();
		}
	}else{
		next();
	}
});

// Ajax
Vue.use({
	install (vue, options) {
		vue.prototype.$axios = axios;
  	}
});

// 设置iview部分全局组件
Vue.component('Button', Button);
Vue.component('Select', Select);
Vue.component('Option', Option);
Vue.component('Modal', Modal);
Vue.component('Col', Col);
Vue.component('Row', Row);
Vue.component('Icon', Icon);
Vue.component('Input', Input);
Vue.component('InputNumber', InputNumber);
Vue.component('Table', Table);
Vue.component('Page', Page);
Vue.component('Form', Form);
Vue.component('FormItem', FormItem);
Vue.component('Upload', Upload);
Vue.component('CheckboxGroup', CheckboxGroup);
Vue.component('Checkbox', Checkbox);
Vue.component("iSwitch", Switch);
Vue.component("CellGroup", CellGroup);
Vue.component("Cell", Cell);
Vue.component("Tabs", Tabs);
Vue.prototype.$Message = Message;
Vue.prototype.$Notice = Notice;
Vue.prototype.$Modal = Modal;

// 第一个是videoJs的样式，后一个是vue-video-player的样式，因为考虑到我其他业务组件可能也会用到视频播放，所以就放在了main.js内
require("video.js/dist/video-js.css");
require("vue-video-player/src/custom-theme.css");
import VideoPlayer from "vue-video-player";
Vue.use(VideoPlayer)

//分页组件
import VueScroller from "vue-scroller"
Vue.use(VueScroller);

// 国际化
Vue.use(VueI18n);

// import 

const i18n = new VueI18n({
	// 语言标识
	locale: 'zh-CN',
	// this.$i18n.locale  通过切换locale的值来实现语言切换
	messages: {
		// 中文语言包
		'zh-CN': require('./commons/lang/zh'),
		// 英文语言包
		'en-US': require('./commons/lang/en')
	}
});
//资源所在地址
if(store.state.env == "production"){
	Vue.prototype.fileBaseUrl = "https://imc2024-bucket.oss-cn-beijing.aliyuncs.com/";         
	Vue.prototype.fromData = {
		'ContentType':'multipart/form-data',
		'Authorization':"Bearer "+ window.localStorage.getItem('access_token')
	};
}else if(store.state.env == "dev"){
	Vue.prototype.fileBaseUrl = "https://imc2024-bucket.oss-cn-beijing.aliyuncs.com/";                   
	Vue.prototype.fromData = {
		'ContentType':'multipart/form-data'
	};
}else if(store.state.env == "test") {
	Vue.prototype.fileBaseUrl = "https://imc2024-bucket.oss-cn-beijing.aliyuncs.com/";                    
	Vue.prototype.fromData = {
		'ContentType':'multipart/form-data',
		'Authorization':"Bearer "+ window.localStorage.getItem('access_token')
	};
}
Vue.prototype.tryCatch = function(jsonStr){
	let tmpObj = null;
	try{
		tmpObj = JSON.parse(jsonStr);
		switch(tmpObj.constructor){
			case "Array":
				tmpObj.forEach((el,i) => {
					tmpObj[i].fileName = (el.fileName || "");
					tmpObj[i].smallFileName = (el.smallFileName || "");
				});
				break;
			case "Object":
				tmpObj.fileName = (tmpObj.fileName || "");
				tmpObj.smallFileName = (el.smallFileName || "");
				break;
		}
		return tmpObj;
	}
	catch(err){
	    return tmpObj;
	}
}
Vue.config.devtools = false;
Vue.config.productionTip = false;
/* eslint-disable no-new */

new Vue({
	el: '#app',
	i18n,
	router,
	store,
	components: { App },
	template: '<App/>'
});
